//#include "stdafx.h"
#include "remoting/protocol_head.h"
#include "basic/base_time.h"
#include "../crypto/crypto.h"

static char *crypt = "AMF_REMOTING_HEAD";
static int crypt_len = 12;
#define _DATA_HEAD DATA_HEAD
bool _DATA_HEAD::CheckMD5()
{
	unsigned char tmp_md5[16];
	MD5_CTX md5_ctx;
	md5_init(&md5_ctx);
	int sz = ((char *)md5 - (char *)this);
	md5_update(&md5_ctx, (unsigned char *)crypt, crypt_len);
	md5_update(&md5_ctx, (unsigned char *)this, sz);
	md5_final(&md5_ctx, tmp_md5);

	return (memcmp (tmp_md5, md5, 16) == 0);
}

void _DATA_HEAD::CreateMD5()
{
	MD5_CTX md5_ctx;
	md5_init(&md5_ctx);
	int sz = ((char *)md5 - (char *)this);
	md5_update(&md5_ctx, (unsigned char *)crypt, crypt_len);
	md5_update(&md5_ctx, (unsigned char *)this, sz);
	md5_final(&md5_ctx, md5);
}

void _DATA_HEAD::Init(char* pVersion)
{
	strncpy(strVersion, pVersion, sizeof(strVersion));
	CreateMD5();
}
